<template>
  <view class="container">
    <!-- <view class="order_num"><text>订单编号：</text>{{result[0].order_num}}</view> -->
    <!-- <view class="goods_unit" :style="{height:pic_h}" v-for="(item,index) in result" :key="index"> -->
    <view class="address" v-on:click="go_address" v-if="address.length==0">
      <view class="none_address">还没有选择地址</view>
      <view class="address_tips">选择地址</view>
    </view>
    <view class="address_unit" v-else>
      <image src="../../static/images/address.png"></image>
      <view class="address_con">
        <view>收货人：{{address[0].addr_name}}</view>
        <view>联系电话：{{address[0].addr_phone}}</view>
        <view>{{address[0].address}}</view>
      </view>
    </view>
    <view class="goods_unit" :style="{height:pic_h}" v-for="(item,index) in result" :key="index">
      <image class="pic" :style="{height:pic_h}" mode="widthFix" :src="url+item.img_url"></image>
      <view class="goods_con" :style="{height:pic_h}">
        <view class="goods_name">{{item.goods_name}}</view>
        <view class="tag">{{item.order_specs_name}}</view>
        <view class="goods_property">￥{{item.order_price}} × {{item.number}}</view>
      </view>
      <view class="price" :style="{height:pic_h}">￥{{item.order_price*item.number}}</view>
    </view>
    <view class="integral">
      <view class="integral_name">运费：</view>
      <view class="integral_value" v-if="result[0].logistics==0">免费包邮</view>
      <view class="integral_value" v-else>￥{{item.logistics}} × {{item.number}}</view>
    </view>
    <view class="remark">
      <view class="remark_title">备注</view>
      <textarea class="text"  maxlength="100" :value="text" data-name="text" @input="input_" placeholder="请输入备注信息"></textarea>
    </view>
    <!--#ifdef APP-PLUS -->
    <!-- <radio-group class="pay_">
      <view class="pay_unit">
        <image src="../../static/images/alipay.png" mode="widthFix"></image>
        <view class="pay_name">支付宝</view>
        <radio value="1" color="#3de9c7"></radio>
      </view>
      <view class="pay_unit">
        <image src="../../static/images/wxpay.png" mode="widthFix"></image>
        <view class="pay_name">微信支付</view>
        <radio value="2" checked="true" color="#3de9c7"></radio>
      </view>
    </radio-group> -->
    <!-- #endif-->
    <radio-group class="pay_" @change="change_pay_type">
      <view class="pay_unit" v-if="integral_type==0">
        <image :src="static_url+'/wxpay.png'" mode="widthFix"></image>
        <view class="pay_name">微信支付</view>
        <radio value="2" checked="true" color="#3de9c7"></radio>
      </view>
      <!--			<view class="pay_unit">-->
      <!--				<image :src="static_url+'/wallet.png'" mode="widthFix"></image>-->
      <!--				<view class="pay_name">余额支付</view>-->
      <!--				<radio value="1" color="#3de9c7"></radio>-->
      <!--			</view>-->
      <view class="pay_unit" v-if="result[0].promotion_499==1">
        <image :src="static_url+'/exchange.png'" mode="widthFix"></image>
        <view class="pay_name">蓝积分兑换</view>
        <radio value="3" color="#3de9c7"></radio>
      </view>
    </radio-group>

    <view class="re" v-on:click="self">重新选择邮寄方式</view>
    <!--  #ifdef  MP-WEIXIN -->
    <!-- #endif-->
    <view class="lh"></view>
    <view class="foot" v-if="integral_type == 0">
      <view class="total" v-if="pay_type!=3">
        <text>共（{{i}}件）</text>
        合计：￥{{pay_achi}}
        <!--				<text class="total" v-if="integral_and_price==1">+{{point_price}}蓝积分</text> -->
      </view>
      <!--			<view class="total" v-else><text>共（{{i}}件）</text>合计：{{pay_achi}}蓝积分</view>-->
      <view class="pay" :id="ids" v-on:click="pay_submit">马上支付</view>
    </view>
    <view class="foot" v-if="integral_type == 0">
      <view class="total" v-if="pay_type!=3">
        <!--        <text>共（{{i}}件）</text>-->
        合计：￥{{pay_achi}}
        <!--				<text class="total" v-if="integral_and_price==1">+{{point_price}}蓝积分</text> -->
      </view>
      <!--			<view class="total" v-else><text>共（{{i}}件）</text>合计：{{pay_achi}}蓝积分</view>-->
      <view class="pay" :id="ids" v-on:click="pay_submit">马上支付</view>
    </view>
    <view class="foot" v-if="integral_type == 1">
      <view class="total" v-if="pay_type!=3">
        <!--        <text>共（{{i}}件）</text>-->
        积分：{{integral_price}}➕¥{{pay_achi}}
        <!--				<text class="total" v-if="integral_and_price==1">+{{point_price}}蓝积分</text> -->
      </view>
      <!--			<view class="total" v-else><text>共（{{i}}件）</text>合计：{{pay_achi}}蓝积分</view>-->
      <view class="pay" :id="ids" v-on:click="integral_submit">马上支付</view>
    </view>
  </view>
</template>
<style>
.pay_{width:96%;margin:10upx 2%;background: #FFFFFF;border-radius: 10upx;}
.pay_unit{width:96%;margin:10upx 2%;display: flex;justify-content: space-between;align-items: center;height: 80upx;}
.pay_unit image{width:40upx;margin-right: 20upx;}
.pay_name{width:80%;font-size:28upx;}
.lh{width:100%;height: 100upx;}
/***********************/
.remark{width:96%;margin:10upx 2%;padding-bottom:20upx;background: #FFFFFF;border-radius: 10upx;}
.remark_title{width:96%;padding-left:4%;line-height: 50upx;font-size: 28upx;font-weight: bold;}
.text{width:88%;padding:0 2%;margin:10upx 4%;border:1px solid #EEEEEE;border-radius:10upx;font-size:28upx;line-height:50upx;height: 100upx;}
page{background: #F4F4F4;}
.container{width:100%;}
.order_num{background: #FFFFFF;width:96%;padding:30upx 2%;font-size: 28upx;font-weight: bold;}
.order_num text{color: #E10000;padding-right: 10upx;}
.integral{width:92%;padding:10upx 2%;margin:10upx 2%;display: flex;justify-content: space-between;align-items: center;background: #FFFFFF;border-radius: 10upx;}
.integral_name{font-size: 24upx;display: flex;justify-content: flex-start;align-items: center;}
.integral_value{font-size: 24upx;color: #FF602B;}
.goods_unit{width:96%;margin:10upx 2%;display: flex;justify-content: space-between;overflow: hidden;
  align-items: center;background: #FFFFFF;border-radius: 10upx;}
.pic{width:30%;}
.goods_con{width:45%;display: flex;flex-direction: column;justify-content: space-between;align-items:flex-start;}
.goods_name{width:98%;padding:20upx 0 0 2%;font-size: 28upx;}
.tag{background: #F4F4F4;padding:5upx 20upx;font-size:28upx;color: #AAAAAA;}
.goods_property{width:98%;padding:0 0 20upx 2%;font-size: 28upx;}
.price{width:15%;text-align: center;font-size: 28upx;font-weight: bold;display: flex;align-items: center;justify-content: center;}

.address_unit{width:96%;margin:0 2% 20upx 2%;height: 160upx;background: #FFFFFF;
  border-radius: 10upx;overflow: hidden;display: flex;justify-content: flex-start;align-items: center;}
.address_unit image{width: 80upx;height: 80upx;}

.address_title image{width:30upx;height:30upx;}
.address_con{width:80%;height: 160upx;display:flex;justify-content: space-between;align-items: flex-start;flex-direction: column;}
.address_con view{padding:0 20upx;font-size:26upx;height: 50upx;line-height:50upx;}

.address{width:92%;padding:10upx 2%;margin:0 2%;border-radius: 10upx;overflow: hidden;background: #FFFFFF;
  display: flex;justify-content: center;align-items: center;flex-direction: column;}
.none_address{width:100%;text-align:center;font-size:28upx;line-height:80upx;}
.address_tips{font-size: 28upx;padding:8upx 30upx;border:1px dashed #3DE9C7;border-radius:8upx;}
.address image{width:40upx;height: 40upx;}
.foot{width:100%;height: 100upx;background: #FFFFFF;position:fixed;bottom: 0;display: flex;justify-content: flex-end;align-items: center;}
.total{height: 100upx;line-height: 100upx;font-size: 28upx;text-align: center;color: #282828;padding-right:20upx;}
.total text{padding-right:15upx;font-size:24upx;color:#AAAAAA;}
.pay{width:30%;height: 80upx;background-image: linear-gradient(#43eac9, #24c3a4);border-radius: 50upx;margin-right:30upx;
  line-height: 80upx;font-size: 30upx;color: #FFFFFF;text-align: center;}
.del{width:25%;height: 100upx;background: #9F9F9F;line-height: 100upx;font-size: 30upx;color:#FFFFFF;text-align: center;}
.total_{height: 100upx;line-height: 50upx;font-size: 30upx;text-align: center;color: #FFFFFF;width:35%;}
.modify{width:100%;line-height: 50upx;font-size:28upx;}
.price_{width:100%;line-height: 50upx;font-size:28upx;text-decoration: line-through;}
.re{font-size: 19px;
  color: #000000;
  text-align: center;
  margin-top: 15%;}
</style>
<script>
import toMpWeixin from '../../js_sdk/wzc-toMpWeixin/toMpWeixin.js';
//#ifdef H5
import wxjs   from '../../jweixin/lib/index.js';
//#endif
export default {
  data() {
    return {
      result:[],
      address:[],
      pic_h:'',
      h:'',
      width:'',
      id:0,
      integral:0,
      self_lifting:'',
      total:0,
      number:0,
      submit_status:1,
      price:0,
      pay_type:2,
      text:'',
      code:'',
      weixin:0,
      display:1,
      type:'',
      i:0,
      ids:'',
      pay_achi:0,
      integral_price:0,
      integral_and_price:0,
      point_price:0,
      blue_integral:0,
      url: getApp().globalData.url,
      static_url:getApp().globalData.static,
      integral_type:0
    }
  },
  onLoad(e) {
    var res = uni.getSystemInfoSync();
    this.goods_w  = 4*150+"px";
    this.h = res.windowHeight+"px";
    this.width = res.windowWidth+"px";
    var w = res.windowWidth;
    this.pic_h = w*0.96*0.3+"px";
    this.id = e.order_id;
    this.integral_type = e.integral_type;
    var order_id = uni.getStorageSync("order_id");
    if(order_id!='')
    {
      this.id = order_id;
    }
    this.type = e.type;
    var that = this;
    //#ifdef H5
    var code  = uni.getStorageSync("code");
    this.code = code;
    //#endif
    this.initialize();
  },
  onShow(){
    this.get_address();

    this.self_lifting  = uni.getStorageSync("self_lifting");
    if (this.self_lifting === '') {
      this.self();
    }
  },
  //#ifdef H5
  mounted() {
    var that = this;
    document.addEventListener("visibilitychange",function(){
      if(document.visibilityState=="visible")
      {
        // that.initialize();
        that.get_address();
      }
    });
    var switchs = uni.getStorageSync("switchs");
    if(switchs==1)
    {
      uni.removeStorageSync("switchs");
      // location.href = "https://www.jdmuguzhid.com/wap?#/pages/mall/order";
    }

  },
  //#endif
  methods: {
    change_pay_type:function(e)
    {
      this.pay_type = parseInt(e.detail.value);
      if(this.pay_type==3)
      {
        this.total  = this.result[0].order_money+1;
      }
    },
    get_openid:function()
    {
      var that = this;
      var member_id = uni.getStorageSync("member_id");
      uni.request({
        url: that.url+'/wechat_snsapi_base_get_openid',
        data: {member_id:member_id,code:this.code,order_id:this.id},
        header: {'Content-Type': 'application/json'},
        success: (res) => {
          // alert(res.data.result.paySign);
          WeixinJSBridge.invoke(
              'getBrandWCPayRequest', {
                "appId":res.data.result.appId,     //公众号ID，由商户传入
                "timeStamp":res.data.result.timeStamp,         //时间戳，自1970年以来的秒数
                "nonceStr":res.data.result.nonceStr, //随机串
                "package":res.data.result.package,
                "signType":"MD5",         //微信签名方式：
                "paySign":res.data.result.paySign //微信签名
              },
              function(res){
                if(res.err_msg == "get_brand_wcpay_request:ok" ){
                  // 使用以上方式判断前端返回,微信团队郑重提示：
                  //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
                }
              });
          /*
          wxjs.config({
            debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: res.data.result.appId,         // 必填，公众号的唯一标识
            timestamp: res.data.result.timeStamp, // 必填，生成签名的时间戳
            nonceStr: res.data.result.nonceStr,   // 必填，生成签名的随机串
            signature: res.data.signature,        // 必填，签名
            jsApiList: ['chooseWXPay','onMenuShareTimeline']            // 必填，需要使用的JS接口列表
          });
          wxjs.chooseWXPay({
            timeStamp: res.data.result.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
            nonceStr: res.data.result.nonceStr,   // 支付签名随机串，不长于 32 位
            package: res.data.result.package,     // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
            signType: res.data.result.signType,   // 微信支付V3的传入RSA,微信支付V2的传入格式与V2统一下单的签名格式保持一致
            paySign: res.data.result.paySign,     // 支付签名
            success: function (ress) {
            // 支付成功后的回调函数
              uni.showModal({
                title:"成功提示",
                content: ress,
                showCancel: false
              });
              console.log('success:' + JSON.stringify(ress));
              // if(ress.errMsg=="requestPayment:ok")
              if (res.errMsg == 'chooseWXPay:ok')
              {
                that.update_order_status(that.id);
              }
            },
            fail:function(ress)
            {
              uni.showModal({
                title:"错误提示111",
                content: ress,
                showCancel: false
              });
              console.log('fail:' + JSON.stringify(ress));
            }
          });
          */
        }
      });
    },
    integral_submit:function(e)
    {
      var id = e.currentTarget.id;
      var that = this;
      var member_id = uni.getStorageSync("member_id");
      var replace_id = uni.getStorageSync("replace_id");
      if(replace_id=="")
      {
        replace_id = 0;
      }
      if(this.submit_status==1)
      {
        console.log(this.address);
        if(this.address.length==0)
        {
          uni.showToast({
            title:"填写收货地址",
            duration:1000
          })
        }
        else
        {
          if(this.pay_type==2)
          {
            if (this.self_lifting === '') {
              uni.showModal({
                title:"操作提示",
                content:"请选择邮寄方式",
                showCancel:false
              })
              return;
            }

            if (that.pay_achi === 0) {
              uni.showModal({
                title:"支付提示",
                content:"确认积分支付？",
                success: (res) => {
                  if(res.confirm)
                  {
                    var type = "integral";
                    that.submit_status = 0;
                    uni.request({
                      url: that.url+'/wechat_integral_pay',
                      data: {integral_price:that.integral_price,member_id:member_id,ids:id,status:that.number,replace_id:replace_id,type:type,self_lifting:that.self_lifting},
                      header: {'Content-Type': 'application/json'},
                      success: (res) => {
                        uni.showModal({
                          title:"操作提示",
                          content:"支付成功?",
                          success: (r) => {
                            if(r.confirm)
                            {
                              uni.redirectTo({
                                url:"/pages/member/order?status=2"
                              })
                            }
                          }
                        })
                      }
                    });
                  }
                }
              })
            } else {

              uni.showModal({
                title:"支付提示",
                content:"确认使用积分加金额支付吗？",
                success: (res) => {
                  if(res.confirm)
                  {
                    //#ifdef MP-WEIXIN
                    var type = "weixin";
                    that.submit_status = 0;
                    uni.request({
                      url: that.url+'/wechat_order_pay',
                      data: {member_id:member_id,ids:id,status:that.number,replace_id:replace_id,type:type,self_lifting:that.self_lifting},
                      header: {'Content-Type': 'application/json'},
                      success: (res) => {
                        console.log(res);
                        //#ifdef MP-WEIXIN
                        that.wechat_pay(id,res.data.result.appId,
                            res.data.result.nonceStr,
                            res.data.result.package,
                            res.data.result.paySign,
                            res.data.result.signType,
                            res.data.result.timeStamp);
                        //#endif
                        //#ifdef APP-PLUS
                        // that.wechat_pay_app(res.data,id);
                        //#endif
                      }
                    });
                    //#endif
                    //#ifdef H5
                    var type = "H5";
                    that.submit_status = 0;
                    if(that.code.length>10)
                    {
                      //微信页面支付
                      that.get_openid();
                    }
                    else
                    {
                      uni.showModal({
                        title:"操作提示",
                        content:"请在微信页面中支付",
                        showCancel:false
                      })
                      return;
                      uni.request({
                        url: that.url+'/wechat_h5_pay',
                        data: {member_id:member_id,order_id:id,status:that.number,replace_id:replace_id,type:type},
                        header: {'Content-Type': 'application/json'},
                        success: (res) => {
                          console.log(res);
                          if(res.data.status==1)
                          {
                            var url = res.data.mweb_url;
                            window.location.href = url;
                          }
                        }
                      });
                    }
                    //#endif
                  }
                  // if(res.confirm)
                  // {
                  //   var type = "integral";
                  //   that.submit_status = 0;
                  //   uni.request({
                  //     url: that.url+'/wechat_order_pay',
                  //     data: {integral_price:that.integral_price,member_id:member_id,ids:id,status:that.number,replace_id:replace_id,type:type,self_lifting:that.self_lifting},
                  //     header: {'Content-Type': 'application/json'},
                  //     success: (res) => {
                  //       uni.showModal({
                  //         title:"操作提示",
                  //         content:"支付成功?",
                  //         success: (r) => {
                  //           if(r.confirm)
                  //           {
                  //             uni.redirectTo({
                  //               url:"/pages/member/order?status=2"
                  //             })
                  //           }
                  //         }
                  //       })
                  //     }
                  //   });
                  // }
                }
              })
            }
            // }
          }
          if(this.pay_type==3)
          {
            var balance = uni.getStorageSync("blue_integral");
            console.log(balance);
            console.log(this.total);//return;
            if(balance<this.total)
            {
              uni.showModal({
                title:"操作提示",
                content:"蓝积分不足，不能用蓝积分进行支付",
                showCancel:false
              })
            }
            else
            {
              uni.showModal({
                title:"操作提示",
                content:"确认使用蓝积分进行支付?",
                success: (r) => {
                  if(r.confirm)
                  {
                    var type = "weixin";
                    that.submit_status = 0;
                    uni.request({
                      url: that.url+'/wechat_blue_integral_exchange_goods',
                      data: {member_id:member_id,order_id:id,status:that.number,replace_id:replace_id,type:type},
                      header: {'Content-Type': 'application/json'},
                      success: (res) => {
                        console.log(res);
                        if(res.data.status==1)
                        {
                          uni.removeStorageSync("replace_id");
                          uni.showToast({
                            title:"支付成功！",
                            duration:1500})
                          uni.redirectTo({
                            url:"/pages/member/order?status=1"
                          })
                        }
                        else
                        {
                          uni.showModal({
                            title:"操作提示",
                            content:res.data.msg,
                            showCancel:false
                          })
                        }
                      }
                    });
                  }
                }
              })
            }
          }
        }
      }
    },
    pay_submit:function(e)
    {
      var id = e.currentTarget.id;
      var that = this;
      var member_id = uni.getStorageSync("member_id");
      var replace_id = uni.getStorageSync("replace_id");
      if(replace_id=="")
      {
        replace_id = 0;
      }
      if(this.submit_status==1)
      {
        console.log(this.address);
        if(this.address.length==0)
        {
          uni.showToast({
            title:"填写收货地址",
            duration:1000
          })
        }
        else
        {
          if(this.pay_type==1)
          {
            var balance = uni.getStorageSync("balance");
            var blue_integral = uni.getStorageSync("blue_integral");
            if (this.self_lifting === '') {
              uni.showModal({
                title:"操作提示",
                content:"请选择邮寄方式",
                showCancel:false
              })
              return;
            }
            console.log(balance);
            console.log(this.total);//return;
            if(balance<this.total)
            {
              uni.showModal({
                title:"操作提示",
                content:"余额不足，不能用余额进行支付",
                showCancel:false
              })
            }
            else if(this.integral_and_price==1 && blue_integral < this.point_price)
            {
              uni.showModal({
                title:"操作提示",
                content:"蓝积分不足",
                showCancel:false
              })
            }
            else
            {
              uni.showModal({
                title:"操作提示",
                content:"确认使用余额支付?",
                success: (r) => {
                  if(r.confirm)
                  {
                    var type = "weixin";
                    that.submit_status = 0;
                    // console.log(id);
                    uni.request({
                      url: that.url+'/wechat_balance_pay',
                      data: {member_id:member_id,ids:id,status:that.number,replace_id:replace_id,type:type,self_lifting:that.self_lifting},
                      header: {'Content-Type': 'application/json'},
                      success: (res) => {
                        console.log(res);
                        if(res.data.status==1)
                        {
                          uni.removeStorageSync("replace_id");
                          uni.showToast({
                            title:"支付成功！",
                            duration:1500})
                          uni.redirectTo({
                            url:"/pages/member/order?status=1"
                          })
                        }
                        else
                        {
                          uni.showModal({
                            title:"操作提示",
                            content:res.data.msg,
                            showCancel:false
                          })
                        }
                      }
                    });
                  }
                }
              })
            }
          }
          if(this.pay_type==2)
          {
            // if (this.integral_and_price==1 && blue_integral < this.point_price)
            // {
            // 	uni.showModal({
            // 		title:"操作提示",
            // 		content:"蓝积分不足",
            // 		showCancel:false
            // 	})
            // }
            // else
            // {
            if (this.self_lifting === '') {
              uni.showModal({
                title:"操作提示",
                content:"请选择邮寄方式",
                showCancel:false
              })
              return;
            }
            uni.showModal({
              title:"支付提示",
              content:"确认微信支付？",
              success: (res) => {
                if(res.confirm)
                {
                  //#ifdef APP-PLUS
                  // var type = "app";
                  // uni.redirectTo({url:"/pages/mall/app_order?order_id="+id})
                  toMpWeixin({
                    appId:'wxb7a354cd32681d5d',
                    gid:'gh_87e8741e177a',
                    path:'pages/mall/order?order_id='+that.id
                  })
                  //#endif
                  //#ifdef MP-WEIXIN
                  var type = "weixin";
                  that.submit_status = 0;
                  uni.request({
                    url: that.url+'/wechat_order_pay',
                    data: {member_id:member_id,ids:id,status:that.number,replace_id:replace_id,type:type,self_lifting:that.self_lifting},
                    header: {'Content-Type': 'application/json'},
                    success: (res) => {
                      console.log(res);
                      //#ifdef MP-WEIXIN
                      that.wechat_pay(id,res.data.result.appId,
                          res.data.result.nonceStr,
                          res.data.result.package,
                          res.data.result.paySign,
                          res.data.result.signType,
                          res.data.result.timeStamp);
                      //#endif
                      //#ifdef APP-PLUS
                      // that.wechat_pay_app(res.data,id);
                      //#endif
                    }
                  });
                  //#endif
                  //#ifdef H5
                  var type = "H5";
                  that.submit_status = 0;
                  if(that.code.length>10)
                  {
                    //微信页面支付
                    that.get_openid();
                  }
                  else
                  {
                    uni.showModal({
                      title:"操作提示",
                      content:"请在微信页面中支付",
                      showCancel:false
                    })
                    return;
                    uni.request({
                      url: that.url+'/wechat_h5_pay',
                      data: {member_id:member_id,order_id:id,status:that.number,replace_id:replace_id,type:type},
                      header: {'Content-Type': 'application/json'},
                      success: (res) => {
                        console.log(res);
                        if(res.data.status==1)
                        {
                          var url = res.data.mweb_url;
                          window.location.href = url;
                        }
                      }
                    });
                  }
                  //#endif
                }
              }
            })
            // }
          }
          if(this.pay_type==3)
          {
            var balance = uni.getStorageSync("blue_integral");
            console.log(balance);
            console.log(this.total);//return;
            if(balance<this.total)
            {
              uni.showModal({
                title:"操作提示",
                content:"蓝积分不足，不能用蓝积分进行支付",
                showCancel:false
              })
            }
            else
            {
              uni.showModal({
                title:"操作提示",
                content:"确认使用蓝积分进行支付?",
                success: (r) => {
                  if(r.confirm)
                  {
                    var type = "weixin";
                    that.submit_status = 0;
                    uni.request({
                      url: that.url+'/wechat_blue_integral_exchange_goods',
                      data: {member_id:member_id,order_id:id,status:that.number,replace_id:replace_id,type:type},
                      header: {'Content-Type': 'application/json'},
                      success: (res) => {
                        console.log(res);
                        if(res.data.status==1)
                        {
                          uni.removeStorageSync("replace_id");
                          uni.showToast({
                            title:"支付成功！",
                            duration:1500})
                          uni.redirectTo({
                            url:"/pages/member/order?status=1"
                          })
                        }
                        else
                        {
                          uni.showModal({
                            title:"操作提示",
                            content:res.data.msg,
                            showCancel:false
                          })
                        }
                      }
                    });
                  }
                }
              })
            }
          }
        }
      }
    },
    wechat_pay_app:function(order_info,order_id)
    {
      var that = this;
      uni.requestPayment({
        provider: 'wxpay',
        orderInfo: order_info,
        success: function (res) {
          console.log(res);
          // console.log(res.errMsg);
          console.log('success:' + JSON.stringify(res));
          if(res.errMsg=="requestPayment:ok")
          {
            that.update_order_status(order_id);
          }
        },
        fail: function (err) {
          console.log('fail:' + JSON.stringify(err));
        },
        complete:function()
        {
          that.submit_status = 1;
        }
      });
    },
    wechat_pay:function(id,appId,nonceStr,Package,paySign,signType,timeStamp)
    {
      var that = this;
      uni.requestPayment({
        provider: 'wxpay',
        timeStamp: timeStamp,
        nonceStr: nonceStr,
        package: Package,
        signType: 'MD5',
        paySign: paySign,
        success: function (res) {
          console.log('success:' + JSON.stringify(res));
          if(res.errMsg=="requestPayment:ok")
          {
            that.update_order_status(id);
          }
        },
        fail: function (err) {
          // console.log('fail:' + JSON.stringify(err));
        },
        complete:function()
        {
          that.submit_status = 1;
        }
      });
    },
    input_:function(e)
    {
      if(e.currentTarget.dataset.name=="text")
      {
        this.text = e.detail.value;
      }
    },
    update_order_status:function(id)
    {
      var that = this;
      var member_id = uni.getStorageSync("member_id");
      uni.request({
        url: this.url+'/wechat_update_order_status',
        data: {member_id:member_id,ids:id,status:this.number,text:this.text,pay_type:that.pay_type},
        header: {'Content-Type': 'application/json'},
        success: (res) => {
          if(res.data.status==1)
          {
            uni.removeStorageSync("replace_id");
            uni.showToast({
              title:"支付成功！",
              duration:3000})
            uni.redirectTo({
              url:"/pages/member/order?status=1"
            })
          }
        }
      });
    },
    pay:function(e)
    {
      var id = e.currentTarget.id;
      console.log(id);
    },
    go_address:function()
    {
      uni.navigateTo({url:"/pages/member/address?type=order&order_id="+this.id})
    },
    self:function()
    {
      var that = this;
      uni.showModal({
        title:"邮寄方式",
        content:"请选择邮寄或者自提",
        cancelText:'邮寄',
        confirmText:'自提',
        success:function (res) {
          if (res.confirm) {
            that.self_lifting = 1;
            uni.setStorageSync("self_lifting",1);
          } else if (res.cancel) {
            uni.setStorageSync("self_lifting",0);
            that.self_lifting = 0;
          }
        }
      })
    },
    get_address:function()
    {
      var member_id  = uni.getStorageSync("member_id");
      var address_id = uni.getStorageSync("address_id");
      console.log(address_id);
      var that = this;
      uni.request({
        url: this.url+'/wechat_get_address',
        data: {member_id:member_id,type:2,address_id:address_id,order_id:this.id},
        header: {'Content-Type': 'application/json'},
        success: (res) => {
          if(res.data.status==1)
          {
            that.address  = res.data.result;
          }
          else
          {
            uni.showModal({
              title:"操作提示",
              content:"需要填写收货地址",
              showCancel:false,
              success: (res) => {
                if(res.confirm)
                {
                  uni.navigateTo({
                    url:"../member/address"
                  })
                }
              }
            })
          }
        }
      });
    },
    initialize:function()
    {
      // uni.requestSubscribeMessage({
      // 	tmplIds: ['InK-z2h-Nncf9MnmSCvM8PSZsEXDONjTX3cLz4HLseM',//订单支付提醒
      // 			  'mkP9bar4566G3uawjVlaiG4jwukCyQfTl1JPxIR-pKI',//签到提醒
      //               'wG0Vy3NOX8s0PmpyDn4BjPDE37oSe_A7yHUV5aiDeok']//优惠活动通知
      // })
      var member_id = uni.getStorageSync("member_id");
      // var member_id = 169187;
      var that = this;
      uni.request({
        url: this.url+'/wechat_get_order',
        data: {id:this.id,member_id:member_id},
        header: {'Content-Type': 'application/json'},
        success: (res) => {
          console.log(res.data);
          //#ifdef H5
          if(res.data.result[0].order_status==1)
          {
            uni.showToast({
              title:"支付成功",
              duration:1500
            })
            uni.redirectTo({
              url:"../member/order"
            })
          }
          //#endif
          that.result = res.data.result;
          that.i = res.data.i;
          that.ids = res.data.ids;
          that.pay_achi = res.data.pay_achi;
          that.integral_price = res.data.integral_price;
          that.total  = that.result[0].order_money;
          that.integral_and_price  = that.result[0].integral_and_price;
          that.point_price  = that.result[0].point_price;
          for(var i=0;i<that.result.length;i++)
          {
            that.number +=that.result[i].number;
          }
          // uni.removeStorageSync("order_id");
        }
      });
    }
  }
}
</script>


